//
//  DiscoverViewController.m
//  MoXiProject
//
//  Created by 周筱雯 on 2017/7/17.
//  Copyright © 2017年 周筱雯. All rights reserved.
//

#import "DiscoverViewController.h"
#import "DisCoverHeaderView.h"
#import "DiscoverCell.h"
#import "BasketballViewController.h"
#import "FootballViewController.h"
#import "NearViewController.h"
#import "HotInformationViewController.h"
#import "ActivityViewController.h"
#import "DatabaseViewController.h"
#import "LLExcelVc.h"
#import "SearchGodViewController.h"

@interface DiscoverViewController ()
<
    UITableViewDelegate,
    UITableViewDataSource,
    DisCoverHeaderViewDelegate
>

@property (nonatomic,strong) DisCoverHeaderView * disView;

@property (nonatomic,strong) UITableView * tableView;

@property (nonatomic,strong) NSMutableArray * disDataArrayList;


@end

@implementation DiscoverViewController

-(DisCoverHeaderView *) disView{
    if (!_disView) {
        _disView  = [[[NSBundle mainBundle] loadNibNamed:@"DisCoverHeaderView" owner:self options:nil] lastObject];
        _disView.delegate=self;
    }
    return _disView;
}

-(UITableView *) tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, DEF_DEVICE_WIDTH, DEF_CONTENT_INTABBAR_HEIGHT - 49) style:UITableViewStylePlain];
        [_tableView setDelegate:self];
        [_tableView setDataSource:self];
        [_tableView setTableHeaderView:self.disView];
        
        [MXUtility setExtraCellLineHidde:_tableView tabHeader:YES tabFooter:NO];
    }
    return _tableView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.view setBackgroundColor:[UIColor whiteColor]];
    [self.view addSubview:self.tableView];
    
}

-(void)ActivityViewClick{
    
    ActivityViewController * activi = [[ActivityViewController alloc] init];
    [self.navigationController pushViewController:activi animated:YES];
}

-(void)InformationViewClick{
    
    HotInformationViewController* vc=[[HotInformationViewController alloc]init];
    vc.hidesBottomBarWhenPushed=YES;
    [self.navigationController pushViewController:vc animated:YES];

}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return [self.disDataArrayList count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [[self.disDataArrayList objectAtIndex:section] count];
}
-(CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 10.f;
}

-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 55;
}
#pragma mark -- 改变header头部的颜色
-(void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section
{
    view.tintColor = DEF_COLOR_F0F0F0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    static NSString * str = @"cell";
    DiscoverCell * cell = [tableView dequeueReusableCellWithIdentifier:str];
    if (!cell) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"DiscoverCell" owner:self options:nil] lastObject];
        [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
    }
   
    [cell disDataSource:[[self.disDataArrayList objectAtIndex:indexPath.section] objectAtIndex:indexPath.row] indexPath:indexPath];
    
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            SearchGodViewController * search = [[SearchGodViewController alloc] init];
            [self.navigationController pushViewController:search animated:YES];
        }
    }
    if (indexPath.section == 1) {
        if (indexPath.row == 0) {
            DatabaseViewController * data = [[DatabaseViewController alloc] init];
            [self.navigationController pushViewController:data animated:YES];
        }
    }
    if (indexPath.section == 2) {
        if (indexPath.row == 0) {
            LLExcelVc * llex = [[LLExcelVc alloc]init];
            [self.navigationController pushViewController:llex animated:YES];
        }
    }
    if (indexPath.section == 3) {
        if (indexPath.row ==0){
            FootballViewController * foot = [[FootballViewController alloc] init];
            [self.navigationController pushViewController:foot animated:YES];
        }
        if (indexPath.row == 1) {
            BasketballViewController * bask = [[BasketballViewController alloc] init];
            [self.navigationController pushViewController:bask animated:YES];
        }
    }
    if (indexPath.section == 4) {
        if (indexPath.row == 0) {
            NearViewController * near = [[NearViewController alloc] init];
           [self.navigationController pushViewController:near animated:YES];
        }
    }
}

-(NSMutableArray *) disDataArrayList{
    
    if (!_disDataArrayList) {
        _disDataArrayList = [[NSMutableArray alloc] initWithCapacity:0];
        
        
        NSDictionary * dict3 = [NSDictionary dictionaryWithObjectsAndKeys:@"sousuo",@"img",
                                @"搜索大神",@"title",nil];
        NSArray * array3 = [[NSArray alloc] initWithObjects:dict3, nil];
        
        NSDictionary * dict4 = [NSDictionary dictionaryWithObjectsAndKeys:@"ziliaoku",@"img",
                                @"资料库信息",@"title",nil];
        NSArray * array1 = [[NSArray alloc] initWithObjects:dict4, nil];
        
        NSDictionary * dict2 = [NSDictionary dictionaryWithObjectsAndKeys:@"zoushi",@"img",
                                @"走势图",@"title",nil];

        NSArray * arraylunt = [[NSArray alloc] initWithObjects:dict2, nil];


        NSDictionary * dict1 = [NSDictionary dictionaryWithObjectsAndKeys:@"zuqiu",@"img",
                                @"足球直播",@"title", nil];
        NSDictionary * dictlan = [NSDictionary dictionaryWithObjectsAndKeys:@"lanqiu",@"img",
                                @"篮球直播",@"title", nil];
        
        NSArray * array2 = [[NSArray alloc] initWithObjects:dict1,dictlan, nil];
        
        
        NSDictionary * userdic = [NSDictionary dictionaryWithObjectsAndKeys:@"zhoubian",@"img",
                                @"附近票点",@"title",nil];
        NSArray * arruser = [NSArray arrayWithObjects:userdic, nil];
        
        
        
        
        [_disDataArrayList addObject:array3];
        [_disDataArrayList addObject:array1];
        [_disDataArrayList addObject:arraylunt];
        [_disDataArrayList addObject:array2];
        [_disDataArrayList addObject:arruser];
        
    }
    return _disDataArrayList;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
